<?php

/**
 * Created by PhpStorm.
 * User: 汪凤杰
 * Date: 2017/1/11
 * Time: 19:55
 */

if (is_file(__DIR__ . '/Common.php')) {
    require_once __DIR__ . '/Common.php';
}

class libs_oss_alioss
{
    private $bucket;
    private $ossClient;
    private $acOssUrl;

    //add by jack on 2016-12-02
    public function uploadToOss($object,$image){
        //上传到oss
        try{
            if(!$this->bucket || !$this->ossClient || !$this->acOssUrl){
                $this->bucket = Common::getBucketName();
                $this->ossClient = Common::getOssClient();
                $this->acOssUrl = Common::getAcOssUrl();
            }
            if (is_null($this->ossClient)) exit("ossClient is_null");
            $this->ossClient->uploadFile($this->bucket, $object, $image);
//					@unlink($image);//删除本地文件
        } catch(OssException $e) {
            printf(__FUNCTION__ . ": FAILED\n");
            printf($e->getMessage() . "\n");
            return;
        }
        //end 上传到oss
    }
    //end add

    //add by jack on 2016-12-02
    public function deleteFromOss($object){
        //上传到oss
        try{
            if(!$this->bucket || !$this->ossClient || !$this->acOssUrl){
                $this->bucket = Common::getBucketName();
                $this->ossClient = Common::getOssClient();
                $this->acOssUrl = Common::getAcOssUrl();
            }
            if (is_null($this->ossClient)) exit("ossClient is_null");
            $this->ossClient->deleteObject($this->bucket, $object);
//					@unlink($image);//删除本地文件
        } catch(OssException $e) {
            printf(__FUNCTION__ . ": FAILED\n");
            printf($e->getMessage() . "\n");
            return;
        }
        //end 上传到oss
    }
    //end add
}